package com.zm.devmag.device.service.Impl;



import java.util.HashMap;
import java.util.List;
import java.util.Map;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.zm.devmag.device.Vo.DeviceDetaiVo;
import com.zm.devmag.device.dao.DeviceDetailMapper;
import com.zm.devmag.device.dao.WarehouseMapper;
import com.zm.devmag.device.po.DeviceDetail;
import com.zm.devmag.device.po.Warehouse;
import com.zm.devmag.device.service.DeviceDetailServer;
import com.zm.devmag.util.ExcelUtil;



@Service
public class DeviceDetailServerImpl implements DeviceDetailServer {
	@Autowired
	private DeviceDetailMapper ddMapper;
	@Autowired
	private WarehouseMapper whMapper;
	public int deleteOneById(Long id){
		return ddMapper.deleteOneById(id);
	}
   
	public DeviceDetaiVo selectById(Long id){
		return ddMapper.selectById(id);
	}
	public List<DeviceDetaiVo>selectAll(Map<String,Object>cond){

		return ddMapper.selectAll(cond);
	}
	public int insertOneDevice(DeviceDetail dd){
		return ddMapper.insertOneDevice(dd);
	}
	public int updateByPrimaryKeySelective(DeviceDetail dd){
		return ddMapper.updateByPrimaryKeySelective(dd);
	}
	public DeviceDetail selectByIdRturnDD(Long id){
		return ddMapper.selectByIdRturnDD(id);
	}
	public	List<String> selectAllDeviceNo(){
		return ddMapper.selectAllDeviceNo();
	}
	public int selectDDConutByDcid(Long dcid){
		return ddMapper.selectDDConutByDcid(dcid);
	}
	public List<DeviceDetaiVo> selectDeviceByLikeNO( Map<String, Object> cond){
		return ddMapper.selectDeviceByLikeNO(cond);
	}
	public DeviceDetaiVo selectDeviceByNo(String para){
		return ddMapper.selectDeviceByNo(para);
	}
	public int insertDeviceDetailBatch(List<DeviceDetail> inlist){
		return ddMapper.insertDeviceDetailBatch(inlist);
	}
	public int checkIsHasByNO(String para){
		return ddMapper.checkIsHasByNO(para);
	}
	public Long getMaxIdValue(){
		return ddMapper.getMaxIdValue();
	}
	public List<DeviceDetaiVo> selectAllNoLimit(Map<String,Object>cond){
		return ddMapper.selectAllNoLimit(cond);
	}
	public void LoadExcelServer(HttpServletRequest request,HttpServletResponse response){
		@SuppressWarnings("unchecked")
		Map<String,Object> cond = (Map<String, Object>) request.getSession().getAttribute("cond");
		String name="设备表";
		if(cond!=null){
			Long wm =(Long)cond.get("wid");
			Warehouse wh = whMapper.selectByPrimaryKey(wm);
			if(wh!=null){
				name= wh.getWhname() +name;
			}else{
				name= "全部"+name;
			}
			String st =(String)cond.get("status");
			if(st!=null){
				switch(st){
				case "0":
					
					break;
				case "1":
					name= name+"--已入库设备";
					break;
				case "2":
					name= name+"--已出库设备";
					break;
				case "3":
					name= name+"--已报废设备";
					break;
				}
			}
		}
		List<DeviceDetaiVo> ddlist=ddMapper.selectAllNoLimit(cond);
        Map<String,String> field = new HashMap<String,String>();
        field.put("0-ccname", "所属类别");
        field.put("1-cfname", "功能类别");
        field.put("2-cdname", "设备类别");
        field.put("3-brand","品牌");
        field.put("4-oldno","旧编号");
        field.put("5-no","编号");
        field.put("6-xhno","型号");
        field.put("7-ccno","出厂编号");
        field.put("8-tcrq", "投产年月");
        field.put("9-zjnx", "折旧年限");
        field.put("10-cgjg", "采购价格");
        field.put("11-oriwhname","初始位置");
        field.put("12-whname","当前位置");
        field.put("13-status","状态");
        field.put("14-remark","备注");
        Map<String,Object> data = new HashMap<String,Object>();
        data.put("listData",ddlist);
        data.put("ziDuan", field);
        ExcelUtil.objListToExcel(name, data,response);
	}
	public int selectAllCount(Map<String, Object> cond){
		return ddMapper.selectAllCount(cond);
	}
}
